﻿#region Using Directives

    using System;
    using System.Linq;
    using System.Xml.Linq;

    using Csla;

    using MarketPulse.BusinessLogic.Core;
    using MarketPulse.Reporting.Core.Criteria;

#endregion

namespace MarketPulse.Reporting.Core
{
    /// <summary>
    /// This class represents a read only instance of a ReportingBranch within the system.
    /// </summary>
    [Serializable]    
    public class ReportingBranchInfo : MarketPulseReadOnlyBase<ReportingBranchInfo>
    {
        #region Constructors

            /// <summary>
            /// Default constructor is private in order to (try to) enforce construction
            /// only via the static factory methods provided.
            /// </summary>
            private ReportingBranchInfo()
            {
            }

        #endregion

        #region Methods
            
            /// <summary>
            /// Fill this objects Results property with data based on the dates supplied.
            /// </summary>
            /// <param name="language">The language identifier (ie. en or fr) to use when localising text from the database.</param>
            /// <param name="currentStartDate">The start date of the reporting period.</param>
            /// <param name="currentEndDate">The end date of the reporting period.</param>
            /// <param name="dataStartDate">The start date of when to retrieve data.</param>
            /// <param name="dataEndDate">The end date of when to retrieve data.</param>
            public void FillResults(string language, DateTime currentStartDate, DateTime currentEndDate, DateTime dataStartDate, DateTime dataEndDate)
            {
                ResultsCriteria criteria = new ResultsCriteria(ClientGUID.Value, this.GUID.Value, language, currentStartDate, currentEndDate, dataStartDate, dataEndDate);
                //LoadProperty(ResultsProperty, ResultsFactory.Create(criteria));
            }

        #endregion

        #region Properties

            /// <summary>
            /// The GUID of the Client this Branch belongs to.
            /// </summary>
            public static PropertyInfo<Nullable<Guid>> ClientGUIDProperty = RegisterProperty<Nullable<Guid>>(p => p.ClientGUID);
            /// <summary>
            /// The GUID of the Client this Branch belongs to.
            /// </summary>
            public Nullable<Guid> ClientGUID
            {
                get { return GetProperty(ClientGUIDProperty); }
            }

            /// <summary>
            /// The GUID of the Area this Branch belongs to.
            /// </summary>
            public static PropertyInfo<Nullable<Guid>> AreaGUIDProperty = RegisterProperty<Nullable<Guid>>(p => p.AreaGUID);
            /// <summary>
            /// The GUID of the Area this Branch belongs to.
            /// </summary>
            public Nullable<Guid> AreaGUID
            {
                get { return GetProperty(AreaGUIDProperty); }
            }

            /// <summary>
            /// The GUID of the Company this Branch belongs to.
            /// </summary>
            public static PropertyInfo<Nullable<Guid>> CompanyGUIDProperty = RegisterProperty<Nullable<Guid>>(p => p.CompanyGUID);
            /// <summary>
            /// The GUID of the Company this Branch belongs to.
            /// </summary>
            public Nullable<Guid> CompanyGUID
            {
                get { return GetProperty(CompanyGUIDProperty); }
            }

            /// <summary>
            /// The LegacyBranchID of this Branch.
            /// </summary>
            public static PropertyInfo<Nullable<long>> LegacyBranchIDProperty = RegisterProperty<Nullable<long>>(p => p.LegacyBranchID);
            /// <summary>
            /// The LegacyBranchID of this Branch.
            /// </summary>
            public Nullable<long> LegacyBranchID
            {
                get { return GetProperty(LegacyBranchIDProperty); }
            }

            /// <summary>
            /// The name of this Branch.
            /// </summary>
            public static PropertyInfo<string> BranchNameProperty = RegisterProperty<string>(p => p.Name);
            /// <summary>
            /// The name of this Branch.
            /// </summary>
            public string Name
            {
                get { return GetProperty(BranchNameProperty); }
            }

            /// <summary>
            /// The BuildingNameOrNumber of this Branch.
            /// </summary>
            public static PropertyInfo<string> BuildingNameOrNumberProperty = RegisterProperty<string>(p => p.BuildingNameOrNumber);
            /// <summary>
            /// The BuildingNameOrNumber of this Branch.
            /// </summary>
            public string BuildingNameOrNumber
            {
                get { return GetProperty(BuildingNameOrNumberProperty); }
            }

            /// <summary>
            /// The AddressLine1 field of this Branch.
            /// </summary>
            public static PropertyInfo<string> AddressLine1Property = RegisterProperty<string>(p => p.AddressLine1);
            /// <summary>
            /// The AddressLine1 field of this Branch.
            /// </summary>
            public string AddressLine1
            {
                get { return GetProperty(AddressLine1Property); }
            }

            /// <summary>
            /// The AddressLine2 field of this Branch.
            /// </summary>
            public static PropertyInfo<string> AddressLine2Property = RegisterProperty<string>(p => p.AddressLine2);
            /// <summary>
            /// The AddressLine2 field of this Branch.
            /// </summary>
            public string AddressLine2
            {
                get { return GetProperty(AddressLine2Property); }
            }

            /// <summary>
            /// The AddressLine3 field of this Branch.
            /// </summary>
            public static PropertyInfo<string> AddressLine3Property = RegisterProperty<string>(p => p.AddressLine3);
            /// <summary>
            /// The AddressLine3 field of this Branch.
            /// </summary>
            public string AddressLine3
            {
                get { return GetProperty(AddressLine3Property); }
            }

            /// <summary>
            /// The AddressLine4 field of this Branch.
            /// </summary>
            public static PropertyInfo<string> AddressLine4Property = RegisterProperty<string>(p => p.AddressLine4);
            /// <summary>
            /// The AddressLine4 field of this Branch.
            /// </summary>
            public string AddressLine4
            {
                get { return GetProperty(AddressLine4Property); }
            }

            /// <summary>
            /// The AddressLine5 field of this Branch.
            /// </summary>
            public static PropertyInfo<string> AddressLine5Property = RegisterProperty<string>(p => p.AddressLine5);
            /// <summary>
            /// The AddressLine5 field of this Branch.
            /// </summary>
            public string AddressLine5
            {
                get { return GetProperty(AddressLine5Property); }
            }

            /// <summary>
            /// The PostCode field of this Branch.
            /// </summary>
            public static PropertyInfo<string> PostCodeProperty = RegisterProperty<string>(p => p.PostCode);
            /// <summary>
            /// The PostCode field of this Branch.
            /// </summary>
            public string PostCode
            {
                get { return GetProperty(PostCodeProperty); }
            }

            /// <summary>
            /// The Memo field of this Branch.
            /// </summary>
            public static PropertyInfo<string> MemoProperty = RegisterProperty<string>(p => p.Memo);
            /// <summary>
            /// The Memo field of this Branch.
            /// </summary>
            public string Memo
            {
                get { return GetProperty(MemoProperty); }
            }

            /// <summary>
            /// The latitudinal coordinate of this Branch.
            /// </summary>
            public static PropertyInfo<Nullable<double>> LatitudeProperty = RegisterProperty<Nullable<double>>(p => p.Latitude);
            /// <summary>
            /// The latitudinal coordinate of this Branch.
            /// </summary>
            public Nullable<double> Latitude
            {
                get { return GetProperty(LatitudeProperty); }
            }

            /// <summary>
            /// The longitudinal coordinate of this Branch.
            /// </summary>
            public static PropertyInfo<Nullable<double>> LongitudeProperty = RegisterProperty<Nullable<double>>(p => p.Longitude);
            /// <summary>
            /// The longitudinal coordinate of this Branch.
            /// </summary>
            public Nullable<double> Longitude
            {
                get { return GetProperty(LongitudeProperty); }
            }

            /// <summary>
            /// A collection of Results for this Branch.
            /// </summary>
            public static PropertyInfo<Results<double>> ResultsProperty = RegisterProperty<Results<double>>(p => p.Results);
            /// <summary>
            /// A collection of Results for this Branch.
            /// </summary>
            public Results<double> Results
            {
                get
                {
                    if(FieldManager.FieldExists(ResultsProperty))
                    {
                        return GetProperty(ResultsProperty);
                    }

                    throw new Exception("You must call FillResults to access this objects Results property.");
                }
            }

        #endregion

    }
}
